package com.ming.yygh.hosp.controller;

import com.ming.yygh.common.result.Result;
import com.ming.yygh.hosp.service.HospitalService;
import com.ming.yygh.model.hosp.Hospital;
import com.ming.yygh.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author Light
 * @date 2021/12/6 9:53
 */
@Api(tags = "医院列表管理")
@RestController
@RequestMapping("admin/hosp/hospital")
//@CrossOrigin
public class HospitalController {

    @Resource
    private HospitalService hospitalService;

    // 医院列表(分页条件查询)
    @ApiOperation(value = "医院列表(分页条件查询)")
    @GetMapping("/list/{page}/{limit}")
    public Result<Page<Hospital>> listHosp(@PathVariable(value = "page") Integer page,
                                           @PathVariable(value = "limit") Integer limit,
                                           HospitalQueryVo hospitalQueryVo) {
        Page<Hospital> pageModel = hospitalService.selectHospPage(page, limit, hospitalQueryVo);
        return Result.ok(pageModel);
    }

    // 更新医院的上线状态
    @ApiOperation(value = "更新医院的上线状态")
    @GetMapping("/updateHospStatus/{id}/{status}")
    public Result<Boolean> updateHospStatus(@PathVariable(value = "id") String id,
                                            @PathVariable(value = "status") Integer status) {
        hospitalService.updateStatus(id, status);
        return Result.ok();
    }

    // 医院的详情信息
    @ApiOperation(value = "医院的详情信息")
    @GetMapping("/showHospDetail/{id}")
    public Result<Map<String, Object>> showHospDetail(@PathVariable(value = "id") String id) {
        Map<String, Object> hospitalMap = hospitalService.getHospById(id);
        return Result.ok(hospitalMap);
    }

}
